﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FitProtocolLibrary
{
    public struct FitMessageHeader
    {
        public byte NormalHeader;
        public byte MessageType;
        public byte Reserved1;
        public byte Reserved2;
        public byte LocalMessageType;
        public byte TimeOffset;

        public byte Header;

        public FitMessageHeader(byte header)
        {
            this.Header = header;
            this.NormalHeader = (byte)((header & 0x80) >> 7);
            if (this.NormalHeader == 0x00)
            {
                this.MessageType = (byte)((header & 0x40) >> 6);
                this.Reserved1 = (byte)((header & 0x20) >> 5);
                this.Reserved2 = (byte)((header & 0x10) >> 4);
                this.LocalMessageType = (byte)((header & 0x0F));
                this.TimeOffset = 0;
            }
            else
            {
                this.MessageType = 0;
                this.Reserved1 = 0;
                this.Reserved2 = 0;
                this.LocalMessageType = (byte)((header & 0x60) >> 5);
                this.TimeOffset = (byte)(header & 0x1F);
            }
        }
    }
}
